Skip to content

🧹 [Code Health] Refactor graphql utility to use handleResponse#59

Closed
is0692vs wants to merge 1 commit intomainfrom
jules-12488802982620083803-22ea21c9
Closed

🧹 [Code Health] Refactor graphql utility to use handleResponse#59
is0692vs wants to merge 1 commit intomainfrom
jules-12488802982620083803-22ea21c9

Conversation

@is0692vs
Copy link
Contributor

🎯 What: The code health issue addressed is the duplication of error-handling logic for HTTP status codes within the graphql utility in src/lib/github.ts.

💡 Why: By refactoring graphql to use the centralized handleResponse helper, we eliminate redundant code responsible for checking rate limit headers and API errors. This improves maintainability since future updates to response processing only need to happen in one place.

Verification: I confirmed that the changes did not alter core functionality by running the full vitest suite via npm run test -- --run. The refactoring cleanly delegates to the helper function without introducing new issues.

Result: The codebase is now more maintainable and readable, with handleResponse uniformly managing HTTP-level error handling across both REST and GraphQL utilities.


PR created automatically by Jules for task 12488802982620083803 started by @is0692vs

Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel
Copy link

vercel bot commented Mar 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
github-user-summary Ready Ready Preview, Comment Mar 13, 2026 4:49am

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request centralizes the HTTP response error handling for GraphQL requests by integrating the existing handleResponse utility. This change streamlines the codebase by eliminating redundant error-checking logic, making the graphql function cleaner and more aligned with the project's standardized approach to API response processing. The primary impact is an improvement in code maintainability and readability without altering core functionality.

Highlights

  • Refactored GraphQL Error Handling: The graphql utility in src/lib/github.ts has been refactored to utilize the shared handleResponse helper for HTTP-level error processing, including rate limiting and general API errors.
  • Improved Code Maintainability: Duplicated error-handling logic for HTTP status codes has been removed, centralizing response processing and enhancing maintainability by requiring future updates to error handling in only one location.
Changelog
  • src/lib/github.ts
    • Removed direct handling of 403 (Rate Limit) and general res.ok checks.
    • Integrated handleResponse to manage HTTP response parsing and error throwing.
Activity
  • PR created automatically by Jules for task 12488802982620083803 started by @is0692vs.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7a3f081e-50d6-4364-b40a-c952ba8052d9

📥 Commits

Reviewing files that changed from the base of the PR and between 3cfdea1 and e7db987.

📒 Files selected for processing (1)
  • src/lib/github.ts

📝 Walkthrough

Summary by CodeRabbit

リリースノート

  • リファクター
    • エラーハンドリングプロセスを統一化し、コードの保守性を向上させました。

このリリースに含まれる変更は、主に内部的な改善です。エンドユーザーに対する機能的な変更や影響はありません。

Walkthrough

GraphQLおよびREST応答処理を一元的なhandleResponseヘルパーに統一しました。graphql関数はHTTP応答検証をhandleResponseに委譲し、GraphQL固有のエラーと空データを検証します。restGetも同様に使用します。

Changes

Cohort / File(s) Summary
レスポンス処理の統一
src/lib/github.ts
GraphQLとREST応答処理をhandleResponseヘルパーに統合。HTTP応答検証を一元化し、GraphQL固有エラーと欠損データの明示的チェックを実装。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 ウサギのコード整理の歌
エラーのみち、ひとすじに
handleResponse の光かな
GraphQL も REST も仲良くて
バグは退治、すっきり晴れ ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed タイトルはPRの主要な変更を明確に要約しており、graphqlユーティリティのリファクタリングとhandleResponseの使用を具体的に説明しています。
Description check ✅ Passed 説明はコード重複の除去、メンテナンス性の向上、テスト検証など、変更セットの実質的な内容と密接に関連しています。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jules-12488802982620083803-22ea21c9
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to improve code health by refactoring the graphql utility to use a shared handleResponse helper, reducing code duplication. While the intention is good, the current implementation introduces a subtle but significant issue in error handling. The shared handleResponse function's logic for handling HTTP 404 errors is not applicable to GraphQL API calls, leading to incorrect error classification. My review includes a comment to address this issue by reverting the change within the graphql function until the helper can be made more flexible.

Comment on lines +67 to +68

const json = await handleResponse<{ data?: T; errors?: { message: string }[] }>(res);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This refactoring to use the shared handleResponse function introduces incorrect error handling for GraphQL calls.

The handleResponse function is designed to throw a UserNotFoundError on an HTTP 404 status, which is appropriate for REST API endpoints that fetch a specific resource (e.g., /users/:username).

However, for the GitHub GraphQL API, an HTTP 404 status indicates a problem with the endpoint itself, not that a user or other entity was not found. A "not found" error in GraphQL is typically returned with an HTTP 200 OK status and an errors array in the JSON payload, which is correctly handled further down in this function.

With this change, a legitimate endpoint error (like a typo in the GraphQL URL or a proxy issue) would be incorrectly reported as a UserNotFoundError, masking the true nature of the problem. The previous implementation correctly treated any non-OK response, including a 404, as a generic GitHubApiError.

To fix this, I recommend restoring the original error handling logic within the graphql function. This is the safest approach until handleResponse can be refactored to be more flexible for different API call types.

  if (res.status === 403) {
    const resetHeader = res.headers.get("X-RateLimit-Reset");
    const resetTimestamp = resetHeader ? parseInt(resetHeader, 10) : Math.floor(Date.now() / 1000) + 3600;
    throw new RateLimitError(resetTimestamp);
  }
  if (!res.ok) {
    const body = await res.text().catch(() => "Unknown error");
    throw new GitHubApiError(body, res.status);
  }
  const json = (await res.json()) as { data?: T; errors?: { message: string }[] };

@is0692vs
Copy link
Contributor Author

This PR is being closed as superseded by #66. The github.ts changes were consolidated there, including the conflict resolution needed to keep the related improvements together.

@is0692vs is0692vs closed this Mar 14, 2026
@google-labs-jules
Copy link
Contributor

This PR is being closed as superseded by #66. The github.ts changes were consolidated there, including the conflict resolution needed to keep the related improvements together.

Understood. Acknowledging that this PR is superseded by #66 and stopping work on this task.

is0692vs added a commit that referenced this pull request Mar 14, 2026
…469035037922359680

📦 [Consolidated] PR #59, #67 の github.ts 改善統合・レビュー指摘対応
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant